import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
//表格信息展示
export const columns: BasicColumn[] = [
  {
    title: '父节点名称',
    dataIndex: 'parentDepartName',
  },
  {
    title: '部门ID',
    dataIndex: 'departmentId',
  },
  {
    title: '公司编码',
    dataIndex: 'corpCode',
  },
  {
    title: '代理人ID',
    dataIndex: 'agentId',
  },
  {
    title: '部门级别',
    dataIndex: 'departmentLevel',
  },
  {
    title: '是否一级部门',
    dataIndex: 'isMainDepartment',
    fixed: 'left',
    customRender: ({ text }) => {
      if (text === '0') {
        return '否';
      } else if (text === '1') {
        return '是';
      }
    },
    // filters: [
    //   { text: '一级部门', value: '1' },
    //   { text: '非一级部门', value: '0' },
    // ],
  },
  {
    title: '父节点ID',
    dataIndex: 'parentId',
  },
  {
    title: '公司ID',
    dataIndex: 'corpId',
  },
  {
    title: '部门名称',
    dataIndex: 'departmentName',
    fixed: 'left',
  },
  {
    title: '部门全称名称',
    dataIndex: 'allDepartName',
  },
  {
    title: '联系人邮件',
    dataIndex: 'contactEmail',
    fixed: 'left',
  },
  {
    title: '联系人姓名',
    dataIndex: 'contactName',
    fixed: 'left',
  },
  {
    title: '联系人电话',
    dataIndex: 'contactPhone',
    fixed: 'left',
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
  },
  {
    title: '部门负责人',
    dataIndex: 'manageName',
    fixed: 'left',
  },
  {
    title: '备注',
    dataIndex: 'remarks',
  },
  {
    title: '部门地址',
    dataIndex: 'address',
  },

  {
    title: '操作员ID',
    dataIndex: 'operatorId',
  },
  {
    title: '状态',
    dataIndex: 'state',
    fixed: 'left',
    width: 80,
    customRender: ({ record }) => {
      const status = record.state;
      const enable = ~~status === 1;
      const color = enable ? 'green' : 'red';
      const text = enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
  },
];
// search框表单
export const searchFormSchema: FormSchema[] = [
  {
    field: `corpCode`,
    label: `公司编号`,
    component: 'Input',
    colProps: {
      xl: 12,
      xxl: 8,
    },
    componentProps: {
      placeholder: '请输入公司编号',
    },
  },
  {
    field: `departmentName`,
    label: `部门名称`,
    component: 'Input',
    colProps: {
      xl: 12,
      xxl: 8,
    },
    componentProps: {
      placeholder: '请输入部门名称',
    },
  },
  {
    field: `contactName`,
    label: `部门联系人`,
    component: 'Input',
    colProps: {
      xl: 12,
      xxl: 8,
    },
    componentProps: {
      placeholder: '请输入部门联系人',
    },
  },
];
// 创建修改部门信息表单
export const formSchema: FormSchema[] = [
  //id
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
    componentProps: {
      readonly: true,
    },
  },
  //父节点名称
  {
    field: 'parentDepartName',
    label: '父节点名称',
    component: 'Input',
    componentProps: {
      placeholder: '请输入父节点名称',
    },
    rules: [
      {
        required: true,
        message: '父节点为必填项',
        trigger: 'blur',
      },
    ],
  },
  // 部门id
  {
    field: 'departmentId',
    label: '部门ID',
    component: 'Input',
    componentProps: {
      placeholder: '请输入部门ID',
    },
    rules: [
      {
        pattern: /^\d*$/,
        required: true,
        message: '部门ID为纯数字',
      },
      {
        required: true,
        message: '部门ID为必填项',
        trigger: 'blur',
      },
    ],
  },
  //  公司编码
  {
    field: 'corpCode',
    label: '公司编码',
    component: 'Select',
    componentProps: {
      placeholder: '请选择公司编码',
      options: [
        {
          label: 'C60600',
          value: 'C60600',
        },
        {
          label: 'C60601',
          value: 'C60601',
        },
      ],
    },
    required: true,
  },
  // 代理人id
  {
    field: 'agentId',
    label: '代理人ID',
    component: 'Input',
    componentProps: {
      placeholder: '请输入代理人ID',
    },
    rules: [
      {
        pattern: /^\d*$/,
        required: true,
        message: '代理人ID为纯数字',
        trigger: 'blur',
      },
      {
        required: true,
        message: '代理人ID为必填项',
        trigger: 'blur',
      },
    ],
  },
  // 部门级别0-9
  {
    field: 'departmentLevel',
    label: '部门级别',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      size: 'small',
      options: [
        { label: '0级', value: 0 },
        { label: '1级', value: 1 },
        { label: '2级', value: 2 },
        { label: '3级', value: 3 },
        { label: '4级', value: 4 },
        { label: '5级', value: 5 },
        { label: '6级', value: 6 },
        { label: '7级', value: 7 },
        { label: '8级', value: 8 },
        { label: '9级', value: 9 },
      ],
    },
    required: true,
  },

  // 是否一级部门
  {
    field: 'isMainDepartment',
    label: '是否一级部门',
    colProps: {
      span: 12,
    },
    component: 'RadioButtonGroup',
    defaultValue: '0',
    componentProps: {
      options: [
        { label: '是', value: '1' },
        { label: '否', value: '0' },
      ],
    },

    required: true,
  },
  //状态（启用/禁用）
  {
    field: 'state',
    label: '状态',
    colProps: {
      span: 12,
    },
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
    required: true,
  },

  // 父节点ID
  {
    field: 'parentId',
    label: '父节点ID',
    component: 'Input',
    componentProps: {
      placeholder: '请输入父节点ID',
    },
    colProps: {
      span: 12,
    },
    rules: [
      {
        pattern: /^\d*$/,
        message: '父节点ID为纯数字',
        required: true,
      },
      {
        required: true,
        message: '父节点ID为必填项',
        trigger: 'blur',
      },
    ],
  },
  // 公司id
  {
    field: 'corpId',
    label: '公司ID',
    colProps: {
      span: 12,
    },
    component: 'Input',
    componentProps: {
      placeholder: '请输入公司ID',
    },
    rules: [
      {
        pattern: /^\d*$/,
        required: true,
        message: '公司ID为纯数字',
      },
      {
        required: true,
        message: '公司ID为必填项',
        trigger: 'blur',
      },
    ],
  },
  // 部门名称
  {
    field: 'departmentName',
    label: '部门名称',
    component: 'Input',
    componentProps: {
      placeholder: '请输入部门名称',
    },
    rules: [
      {
        required: true,
        message: '部门名称为必填项',
        trigger: 'blur',
      },
    ],
  },
  // 部门全称名称
  {
    field: 'allDepartName',
    label: '部门全称名称',
    component: 'Cascader',
    componentProps: {
      placeholder: '请选择部门全称',
      options: [
        {
          label: '技术中心(1级部门)',
          value: '技术中心(1级部门)',
          children: [
            {
              label: '技术一部(2级部门)',
              value: '技术一部(2级部门)',
              children: [
                {
                  label: '技术一组(3级部门)',
                  value: '技术一组(3级部门)',
                },
              ],
            },
          ],
        },
      ],
    },
    required: true,
  },

  // required: true,

  // 联系人邮箱
  {
    field: 'contacteMail',
    label: '联系人邮件',
    component: 'Input',
    componentProps: {
      placeholder: '请输入联系人邮件',
    },
    rules: [
      {
        type: 'email',
        required: true,
        message: '请输入正确邮箱',
        trigger: 'blur',
      },
    ],
  },
  // 联系人姓名
  {
    field: 'contactName',
    label: '联系人姓名',
    component: 'Input',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请输入联系人姓名',
    },
    rules: [
      {
        required: true,
        message: '联系人姓名为必填项',
        trigger: 'blur',
      },
    ],
    required: true,
  },
  // 联系人电话
  {
    field: 'contactPhone',
    label: '联系人电话',
    component: 'Input',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请输入联系人电话',
    },
    rules: [
      {
        required: true,
        message: '手机号为必填项',
        trigger: 'blur',
      },
      {
        pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
        message: '请输入正确的手机号码',
        trigger: 'blur',
      },
    ],
  },
  // 部门负责人
  {
    field: 'manageName',
    label: '部门负责人',
    component: 'Input',
    componentProps: {
      placeholder: '请输入部门负责人',
    },
    rules: [
      {
        required: true,
        message: '部门负责人为必填项',
        trigger: 'blur',
      },
    ],
  },
  // 部门地址
  {
    field: 'address',
    label: '部门地址',
    component: 'Input',
    // required: true,
    componentProps: {
      placeholder: '请输入地址',
    },
  },
  // 备注
  {
    field: 'remarks',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '备注信息',
    },
  },
  {
    field: 'operatorId',
    label: '操作员id',
    component: 'Input',
    ifShow: false,
  },
];
